package com.cnebula.dataprocess.hive.job.consumer;

import org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.starter.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cnebula.dataprocess.common.hive.HivePurge;
import com.cnebula.dataprocess.hive.job.serivce.HiveService;
import com.google.gson.Gson;

@Service
@RocketMQMessageListener(topic = "hive-purge-topic", consumerGroup = "hive-purge-consumer")
public class HivePurgeConsumer  implements RocketMQListener<HivePurge> {
	
	private static final Logger log = LoggerFactory.getLogger(HivePurgeConsumer.class);

	private Gson gson = new Gson();
	
	@Autowired
	HiveService hiveService;
	
	@Override
	public void onMessage(HivePurge arg0) {
		
		log.info("=============================receive hive purge job ============================");
		log.info(gson.toJson(arg0));
		log.info("===================================================================================");
		
		String sql = arg0.getSql();
		String jobId = arg0.getJobId();
		String taskId = arg0.getTaskId();
		hiveService.purge(taskId, jobId, sql);
	}


}
